/**
 * Licensee: Universidad del Pais Vasco
 * License Type: Academic
 */
package ormsamples;

import org.orm.*;
public class ListBibliotecaData {
	private static final int ROW_COUNT = 100;
	
	public void listTestData() throws PersistentException {
		System.out.println("Listing Recurso...");
		orm.Recurso[] ormRecursos = orm.RecursoDAO.listRecursoByQuery(null, null);
		int length = Math.min(ormRecursos.length, ROW_COUNT);
		for (int i = 0; i < length; i++) {
			System.out.println(ormRecursos[i]);
		}
		System.out.println(length + " record(s) retrieved.");
		
		System.out.println("Listing Usuario...");
		orm.Usuario[] ormUsuarios = orm.UsuarioDAO.listUsuarioByQuery(null, null);
		length = Math.min(ormUsuarios.length, ROW_COUNT);
		for (int i = 0; i < length; i++) {
			System.out.println(ormUsuarios[i]);
		}
		System.out.println(length + " record(s) retrieved.");
		
	}
	
	public void listByCriteria() throws PersistentException  {
		System.out.println("Listing Recurso by Criteria...");
		orm.RecursoCriteria lormRecursoCriteria = new orm.RecursoCriteria();
		// Please uncomment the follow line and fill in parameter(s) 
		//lormRecursoCriteria.id.eq();
		lormRecursoCriteria.setMaxResults(ROW_COUNT);
		orm.Recurso[] ormRecursos = lormRecursoCriteria.listRecurso();
		int length =ormRecursos== null ? 0 : Math.min(ormRecursos.length, ROW_COUNT); 
		for (int i = 0; i < length; i++) {
			 System.out.println(ormRecursos[i]);
		}
		System.out.println(length + " Recurso record(s) retrieved."); 
		
		System.out.println("Listing Usuario by Criteria...");
		orm.UsuarioCriteria lormUsuarioCriteria = new orm.UsuarioCriteria();
		// Please uncomment the follow line and fill in parameter(s) 
		//lormUsuarioCriteria.rut.eq();
		lormUsuarioCriteria.setMaxResults(ROW_COUNT);
		orm.Usuario[] ormUsuarios = lormUsuarioCriteria.listUsuario();
		length =ormUsuarios== null ? 0 : Math.min(ormUsuarios.length, ROW_COUNT); 
		for (int i = 0; i < length; i++) {
			 System.out.println(ormUsuarios[i]);
		}
		System.out.println(length + " Usuario record(s) retrieved."); 
		
	}
	
	public static void main(String[] args) {
		try {
			ListBibliotecaData listBibliotecaData = new ListBibliotecaData();
			try {
				listBibliotecaData.listTestData();
				//listBibliotecaData.listByCriteria();
			}
			finally {
				orm.BibliotecaPersistentManager.instance().disposePersistentManager();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
